import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:xws/utils/theme_util.dart';
import 'package:xws/utils/tools_util.dart';
import 'package:xws/widgets/app_btn.dart';
import 'package:xws/widgets/app_img.dart';

/// 视频播放
class PlayVideo extends StatelessWidget {
  const PlayVideo({
    Key? key,
    required this.path,
    required this.cover,
    this.width,
    this.height = 100,
  }) : super(key: key);

  final double? width;
  final double height;

  final String path;

  final String cover;

  /// 预览内容
  Future<void> _preView(BuildContext context) async {
    await assetsViewer(context, <String>[path], isVideo: true);
  }

  @override
  Widget build(BuildContext context) {
    return AppBtn.noPadding(
      onTap: () => _preView(context),
      width: width,
      height: height,
      radius: 10,
      clipBehavior: Clip.antiAlias,
      color: canvas(context),
      child: Stack(
        alignment: Alignment.center,
        children: <Widget>[
          AppImg.fitCover(
            width: double.infinity,
            url: cover,
          ),
          const SizedBox.expand(
            child: ColoredBox(color: Colors.black54),
          ),
          Padding(
            padding: const EdgeInsets.only(left: 20),
            child: Row(
              children: <Widget>[
                Icon(
                  Icons.play_circle_fill_rounded,
                  size: 40,
                  color: white(context),
                ),
                const SizedBox(width: 10),
                const Text(
                  '观看介绍视频',
                  style: TextStyle(
                    fontSize: 14,
                    color: Colors.white,
                    fontWeight: FontWeight.bold,
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}
